package com.longjianghuasheng.logistics.business.freight

import androidx.databinding.ObservableInt
import androidx.lifecycle.MutableLiveData
import com.longjianghuasheng.logistics.data.model.bean.ApiResponseNoData
import com.longjianghuasheng.logistics.ext.checkPhone
import com.longjianghuasheng.logistics.ext.commit
import com.longjianghuasheng.logistics.ext.commit2
import com.longjianghuasheng.logistics.ext.judge
import com.longjianghuasheng.logistics.network.apiService
import com.longjianghuasheng.logistics.repository.request.HttpRequestCoroutine
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel

class CooperateViewModel : BaseViewModel() {

    var names = ""
    var address = ""
    var contact = ""
    var mobile = ""
    var code = ""
    var card_front = ""
    var card_back = ""
    var books = ""
    var isCompany = false
    val notify by lazy {
        MutableLiveData<ApiResponseNoData>()
    }


    val startCount by lazy {
        ObservableInt()
    }


    fun onGetCode() {

        if (!checkPhone(mobile)) return
        commit({ apiService.get_code(mobile, 2) }, {
            startCount.set(60)
        })
    }

    fun team_work() {

        var isSuccess = false
        when {
            names.judge("请输入公司名称") -> {}
            address.judge("请输入公司地址") -> {}
            contact.judge("请输入联系人姓名") -> {}
            !checkPhone(mobile) -> {}
            code.judge("请输入验证码") -> {}

            card_front.judge("请上传身份证正面") -> {}
            card_back.judge("请上传身份证背面") -> {}
            books.judge("请上传营业执照") -> {}

            else -> isSuccess = true
        }

        if (!isSuccess) return




        commit2({
            HttpRequestCoroutine.team_work(
                names,
                address,
                contact,
                mobile,
                code,
                card_front,
                card_back,
                books,
                isCompany
            )
        }, notify)
    }
}